package com.hanoi.wiki.model;

import java.io.Serializable;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import com.hanoi.wiki.model.json.CategorySubTypeJson;

@Entity
@Table(name="CATEGORY_SUB_TYPE")
public class CategorySubType implements Serializable{	

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	public CategorySubType() {
		
	}
	
	public CategorySubType(CategorySubTypeJson json) {
		this.subTypeName 	= json.getSubTypeName();
		this.status 		= json.getStatus();
	}
	
	@Id
	@Column(name="ID")
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Integer id;
	
	@Column(name="SUB_TYPE_NAME", length = 200, unique = true, nullable = false)
	private String subTypeName;
	
	@Column(name="STATUS")
	private Integer status;
	
	@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinTable(name = "CATTYPE_CATSUBTYPE", joinColumns = { @JoinColumn(name = "CAT_SUBTYPE_ID")}, inverseJoinColumns = {@JoinColumn(name = "CAT_TYPE_ID")})
	private List<CategoryType> categoryTypes;
	
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getSubTypeName() {
		return subTypeName;
	}
	public void setSubTypeName(String subTypeName) {
		this.subTypeName = subTypeName;
	}
	public Integer getStatus() {
		return status;
	}
	public void setStatus(Integer status) {
		this.status = status;
	}
	public List<CategoryType> getCategoryTypes() {
		return categoryTypes;
	}
	public void setCategoryTypes(List<CategoryType> categoryTypes) {
		this.categoryTypes = categoryTypes;
	}	
}	
